<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" @submit.native.prevent v-show="showSearch" label-width="68px">
<!--      <el-form-item label="发送方" prop="send">-->
<!--        <el-input-->
<!--          v-model="queryParams.send"-->
<!--          placeholder="请输入发送方"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="接收方" prop="receive">-->
<!--        <el-input-->
<!--          v-model="queryParams.receive"-->
<!--          placeholder="请输入接收方"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="task编码" prop="taskCode" label-width="60">
        <el-input
          v-model="queryParams.taskCode"
          placeholder="请输入task编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="方法名" prop="method">
        <el-input
          v-model="queryParams.method"
          placeholder="请输入方法名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="参数" prop="param">
        <el-input
          v-model="queryParams.param"
          placeholder="请输入参数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="agv路径" prop="agvUrl">
        <el-input
          v-model="queryParams.agvUrl"
          placeholder="请输入agv路径"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['wcs:agvRcsRecord:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['wcs:agvRcsRecord:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['wcs:agvRcsRecord:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['wcs:agvRcsRecord:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="agvRcsRecordList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" type="index" width="50" />
      <el-table-column label="发送方" align="center" prop="send"  min-width="80" show-overflow-tooltip />
      <el-table-column label="接收方" align="center" prop="receive"  min-width="80" show-overflow-tooltip />
      <el-table-column label="task编码" align="center" prop="taskCode"  min-width="300" show-overflow-tooltip />
      <el-table-column label="方法名" align="center" prop="method"  min-width="150" show-overflow-tooltip />
      <el-table-column label="参数" align="center" prop="param"  min-width="150" show-overflow-tooltip />
      <el-table-column label="agv路径" align="center" prop="agvUrl"  min-width="120" show-overflow-tooltip />
      <el-table-column label="agv调用状态" align="center" prop="status"  min-width="120" show-overflow-tooltip />
      <el-table-column label="返回值" align="center" prop="response"  min-width="120" show-overflow-tooltip/>
      <el-table-column label="创建人" align="center" prop="createBy" min-width="100"/>
      <el-table-column label="创建时间" align="center" prop="createTime" min-width="152" />
      <el-table-column label="最后更新人" align="center" prop="updateBy" min-width="100"/>
      <el-table-column label="最后更新时间" align="center" prop="updateTime" min-width="152" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改rcs调用记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="发送方" prop="send">
          <el-input v-model="form.send" placeholder="请输入发送方" />
        </el-form-item>
        <el-form-item label="接收方" prop="receive">
          <el-input v-model="form.receive" placeholder="请输入接收方" />
        </el-form-item>
        <el-form-item label="task编码" prop="taskCode">
          <el-input v-model="form.taskCode" placeholder="请输入task编码" />
        </el-form-item>
        <el-form-item label="方法名" prop="method">
          <el-input v-model="form.method" placeholder="请输入方法名" />
        </el-form-item>
        <el-form-item label="参数" prop="param">
          <el-input v-model="form.param" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="agv路径" prop="agvUrl">
          <el-input v-model="form.agvUrl" placeholder="请输入agv路径" />
        </el-form-item>
        <el-form-item label="返回值" prop="response">
          <el-input v-model="form.response" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="排序" prop="sort">
          <el-input v-model="form.sort" placeholder="请输入排序" />
        </el-form-item>
        <el-form-item label="版本" prop="version">
          <el-input v-model="form.version" placeholder="请输入版本" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAgvRcsRecord, getAgvRcsRecord, delAgvRcsRecord, addAgvRcsRecord, updateAgvRcsRecord } from "@/api/wcs/agvRcsRecord";

export default {
  name: "AgvRcsRecord",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      selections: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // rcs调用记录表格数据
      agvRcsRecordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        send: null,
        receive: null,
        taskCode: null,
        method: null,
        param: null,
        agvUrl: null,
        status: null,
        response: null,
        errorMsg: null,
        sort: null,
        version: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        sort: [
          { required: true, message: "排序不能为空", trigger: "blur" }
        ],
        version: [
          { required: true, message: "版本不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询rcs调用记录列表 */
    getList() {
      this.loading = true;
      listAgvRcsRecord(this.queryParams).then(response => {
        this.agvRcsRecordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        send: null,
        receive: null,
        taskCode: null,
        method: null,
        param: null,
        agvUrl: null,
        status: "0",
        response: null,
        errorMsg: null,
        sort: null,
        version: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        delFlag: null,
        createBy: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.selections = selection
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加rcs调用记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getAgvRcsRecord(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改rcs调用记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAgvRcsRecord(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAgvRcsRecord(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.resetQuery();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除"' + ids.length + '"条数据项？').then(function() {
        return delAgvRcsRecord(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('wcs/agvRcsRecord/export', {
        ...this.queryParams
      }, `agvRcsRecord_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
